package com.nwpu.server.learning.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nwpu.server.common.response.PageUtils;
import com.nwpu.server.common.response.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.nwpu.server.learning.entity.NetworkEntity;
import com.nwpu.server.learning.service.NetworkService;


/**
 * 网站旭日图模块 网络热编码
 *
 * @author YuXingZh
 * @email 617058979@qq.com
 * @date 2022-09-17 11:07:46
 */
@RestController
@RequestMapping("learning/network")
public class NetworkController {
    @Autowired
    private NetworkService networkService;

    /**
     * 查询旭日图数据并附带ID
     */
    @GetMapping("/listTree")
    public R listTree() {
        // 查询属性图数据
        List<NetworkEntity> listTree = networkService.listTree();
        return R.ok().put("listTree", listTree);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = networkService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        NetworkEntity network = networkService.getById(id);

        return R.ok().put("network", network);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody NetworkEntity network) {
        networkService.save(network);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody NetworkEntity network) {
        networkService.updateById(network);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        networkService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
